<template>
    <div class="global_header">
        <div class="headers_left_title">
            <span>Forum {{ $store.state.Count }}</span>
        </div>
        <div class="search_input">
            <el-input placeholder="请输入内容" v-model="searchKey" class="input-with-select">
                <el-button slot="append" icon="el-icon-search" @click="add"></el-button>
            </el-input>
        </div>
        <div class="headers_right_buttons">
            <div class="headers_right_dropdown" v-if="isShow">
                <span class="el-dropdown-link">
                    <router-link to="/login" style="color:white;text-decoration: none;">登录</router-link>
                </span>
            </div>
            <div v-else style="float: left;">
            <el-dropdown>
                <span class="el-dropdown-link">
                  用户中心<i class="el-icon-arrow-down el-icon--right"></i>
                </span>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item>个人信息</el-dropdown-item>
                  <el-dropdown-item>切换用户</el-dropdown-item>
                  <el-dropdown-item @click.native="LoginOut">退出</el-dropdown-item>
                </el-dropdown-menu>
            </el-dropdown>
            </div>
            <div class="headers_right_dropdown">
                <span class="el-dropdown-link">
                    <router-link to="/register" style="color:white;text-decoration: none;">注册</router-link>
                </span>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    name: "Header",
    data(){
        return {
            searchKey: "",
            isShow: false,
        }
    },
    methods:{
        LoginOut: function (){
          // 清空localStorage
          console.log('清空localStorage!')
          // 路由跳转'/'
          this.$router.push('/');
        },
        add(){
          this.$store.commit('increment');
        }
    }
}
</script>

<style scoped>

/** scopes */
  .el-dropdown-link {
    cursor: pointer;
    color: white;
  }
  .el-icon-arrow-down {
    font-size: 12px;
  }
  .el-dropdown{
      font-size: 16px;
  }
/** scopes end */

.global_header{
    width: 100%;
    height: 50px;
    background-color: #545c64;
    color: white;
}
.headers_left_title{
    float: left;
    width: 10%;
    margin-left: 10px;
    line-height: 50px;
}
.headers_left_title span{
    font-size: 20px;
    font-weight: 700;
}
.search_input{
    width: 40%;
    margin-left: 20%;
    line-height: 50px;
    float: left;
}
.headers_right_buttons{
    float: right;
    line-height: 50px;
}
.headers_right_buttons span{
    margin-left: 25px;
}
.headers_right_buttons .headers_right_dropdown{
    margin-right: 10px;
    float: left;
}
</style>